# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -mtriple=i386-linux-gnu -run-pass=instruction-select -verify-machineinstrs %s -o - | FileCheck %s

--- |
  ; ModuleID = 'srem.ll'
  source_filename = "srem.ll"
  target datalayout = "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128"
  target triple = "i386--linux-gnu"

  define i8 @test_srem_i8(i8 %arg1, i8 %arg2) {
    %res = srem i8 %arg1, %arg2
    ret i8 %res
  }

  define i16 @test_srem_i16(i16 %arg1, i16 %arg2) {
    %res = srem i16 %arg1, %arg2
    ret i16 %res
  }

  define i32 @test_srem_i32(i32 %arg1, i32 %arg2) {
    %res = srem i32 %arg1, %arg2
    ret i32 %res
  }

...
---
name:            test_srem_i8
alignment:       16
exposesReturnsTwice: false
legalized:       true
regBankSelected: true
selected:        false
failedISel:      false
tracksRegLiveness: true
registers:
  - { id: 0, class: gpr, preferred-register: '' }
  - { id: 1, class: gpr, preferred-register: '' }
  - { id: 2, class: gpr, preferred-register: '' }
  - { id: 3, class: gpr, preferred-register: '' }
  - { id: 4, class: gpr, preferred-register: '' }
liveins:
frameInfo:
  isFrameAddressTaken: false
  isReturnAddressTaken: false
  hasStackMap:     false
  hasPatchPoint:   false
  stackSize:       0
  offsetAdjustment: 0
  maxAlignment:    4
  adjustsStack:    false
  hasCalls:        false
  stackProtector:  ''
  maxCallFrameSize: 4294967295
  hasOpaqueSPAdjustment: false
  hasVAStart:      false
  hasMustTailInVarArgFunc: false
  localFrameSize:  0
  savePoint:       ''
  restorePoint:    ''
fixedStack:
  - { id: 0, type: default, offset: 4, size: 1, alignment: 4, stack-id: default,
      isImmutable: true, isAliased: false, callee-saved-register: '', callee-saved-restored: true,
      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
  - { id: 1, type: default, offset: 0, size: 1, alignment: 16, stack-id: default,
      isImmutable: true, isAliased: false, callee-saved-register: '', callee-saved-restored: true,
      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
stack:
constants:
body:             |
  bb.1 (%ir-block.0):
    ; CHECK-LABEL: name: test_srem_i8
    ; CHECK: [[MOV8rm:%[0-9]+]]:gr8 = MOV8rm %fixed-stack.0, 1, $noreg, 0, $noreg :: (invariant load (s8) from %fixed-stack.0, align 16)
    ; CHECK: [[MOV8rm1:%[0-9]+]]:gr8 = MOV8rm %fixed-stack.1, 1, $noreg, 0, $noreg :: (invariant load (s8) from %fixed-stack.1, align 4)
    ; CHECK: $ax = MOVSX16rr8 [[MOV8rm]]
    ; CHECK: IDIV8r [[MOV8rm1]], implicit-def $al, implicit-def $ah, implicit-def $eflags, implicit $ax
    ; CHECK: [[COPY:%[0-9]+]]:gr8 = COPY $ah
    ; CHECK: $al = COPY [[COPY]]
    ; CHECK: RET 0, implicit $al
    %2:gpr(p0) = G_FRAME_INDEX %fixed-stack.1
    %0:gpr(s8) = G_LOAD %2(p0) :: (invariant load (s8) from %fixed-stack.1, align 16)
    %3:gpr(p0) = G_FRAME_INDEX %fixed-stack.0
    %1:gpr(s8) = G_LOAD %3(p0) :: (invariant load (s8) from %fixed-stack.0, align 4)
    %4:gpr(s8) = G_SREM %0, %1
    $al = COPY %4(s8)
    RET 0, implicit $al

...
---
name:            test_srem_i16
alignment:       16
exposesReturnsTwice: false
legalized:       true
regBankSelected: true
selected:        false
failedISel:      false
tracksRegLiveness: true
registers:
  - { id: 0, class: gpr, preferred-register: '' }
  - { id: 1, class: gpr, preferred-register: '' }
  - { id: 2, class: gpr, preferred-register: '' }
  - { id: 3, class: gpr, preferred-register: '' }
  - { id: 4, class: gpr, preferred-register: '' }
liveins:
frameInfo:
  isFrameAddressTaken: false
  isReturnAddressTaken: false
  hasStackMap:     false
  hasPatchPoint:   false
  stackSize:       0
  offsetAdjustment: 0
  maxAlignment:    4
  adjustsStack:    false
  hasCalls:        false
  stackProtector:  ''
  maxCallFrameSize: 4294967295
  hasOpaqueSPAdjustment: false
  hasVAStart:      false
  hasMustTailInVarArgFunc: false
  localFrameSize:  0
  savePoint:       ''
  restorePoint:    ''
fixedStack:
  - { id: 0, type: default, offset: 4, size: 2, alignment: 4, stack-id: default,
      isImmutable: true, isAliased: false, callee-saved-register: '', callee-saved-restored: true,
      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
  - { id: 1, type: default, offset: 0, size: 2, alignment: 16, stack-id: default,
      isImmutable: true, isAliased: false, callee-saved-register: '', callee-saved-restored: true,
      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
stack:
constants:
body:             |
  bb.1 (%ir-block.0):
    ; CHECK-LABEL: name: test_srem_i16
    ; CHECK: [[MOV16rm:%[0-9]+]]:gr16 = MOV16rm %fixed-stack.0, 1, $noreg, 0, $noreg :: (invariant load (s16) from %fixed-stack.0, align 16)
    ; CHECK: [[MOV16rm1:%[0-9]+]]:gr16 = MOV16rm %fixed-stack.1, 1, $noreg, 0, $noreg :: (invariant load (s16) from %fixed-stack.1, align 4)
    ; CHECK: $ax = COPY [[MOV16rm]]
    ; CHECK: CWD implicit-def $ax, implicit-def $dx, implicit $ax
    ; CHECK: IDIV16r [[MOV16rm1]], implicit-def $ax, implicit-def $dx, implicit-def $eflags, implicit $ax, implicit $dx
    ; CHECK: [[COPY:%[0-9]+]]:gr16 = COPY $dx
    ; CHECK: $ax = COPY [[COPY]]
    ; CHECK: RET 0, implicit $ax
    %2:gpr(p0) = G_FRAME_INDEX %fixed-stack.1
    %0:gpr(s16) = G_LOAD %2(p0) :: (invariant load (s16) from %fixed-stack.1, align 16)
    %3:gpr(p0) = G_FRAME_INDEX %fixed-stack.0
    %1:gpr(s16) = G_LOAD %3(p0) :: (invariant load (s16) from %fixed-stack.0, align 4)
    %4:gpr(s16) = G_SREM %0, %1
    $ax = COPY %4(s16)
    RET 0, implicit $ax

...
---
name:            test_srem_i32
alignment:       16
exposesReturnsTwice: false
legalized:       true
regBankSelected: true
selected:        false
failedISel:      false
tracksRegLiveness: true
registers:
  - { id: 0, class: gpr, preferred-register: '' }
  - { id: 1, class: gpr, preferred-register: '' }
  - { id: 2, class: gpr, preferred-register: '' }
  - { id: 3, class: gpr, preferred-register: '' }
  - { id: 4, class: gpr, preferred-register: '' }
liveins:
frameInfo:
  isFrameAddressTaken: false
  isReturnAddressTaken: false
  hasStackMap:     false
  hasPatchPoint:   false
  stackSize:       0
  offsetAdjustment: 0
  maxAlignment:    4
  adjustsStack:    false
  hasCalls:        false
  stackProtector:  ''
  maxCallFrameSize: 4294967295
  hasOpaqueSPAdjustment: false
  hasVAStart:      false
  hasMustTailInVarArgFunc: false
  localFrameSize:  0
  savePoint:       ''
  restorePoint:    ''
fixedStack:
  - { id: 0, type: default, offset: 4, size: 4, alignment: 4, stack-id: default,
      isImmutable: true, isAliased: false, callee-saved-register: '', callee-saved-restored: true,
      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
  - { id: 1, type: default, offset: 0, size: 4, alignment: 16, stack-id: default,
      isImmutable: true, isAliased: false, callee-saved-register: '', callee-saved-restored: true,
      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
stack:
constants:
body:             |
  bb.1 (%ir-block.0):
    ; CHECK-LABEL: name: test_srem_i32
    ; CHECK: [[MOV32rm:%[0-9]+]]:gr32 = MOV32rm %fixed-stack.0, 1, $noreg, 0, $noreg :: (invariant load (s32) from %fixed-stack.0, align 16)
    ; CHECK: [[MOV32rm1:%[0-9]+]]:gr32 = MOV32rm %fixed-stack.1, 1, $noreg, 0, $noreg :: (invariant load (s32) from %fixed-stack.1)
    ; CHECK: $eax = COPY [[MOV32rm]]
    ; CHECK: CDQ implicit-def $eax, implicit-def $edx, implicit $eax
    ; CHECK: IDIV32r [[MOV32rm1]], implicit-def $eax, implicit-def $edx, implicit-def $eflags, implicit $eax, implicit $edx
    ; CHECK: [[COPY:%[0-9]+]]:gr32 = COPY $edx
    ; CHECK: $eax = COPY [[COPY]]
    ; CHECK: RET 0, implicit $eax
    %2:gpr(p0) = G_FRAME_INDEX %fixed-stack.1
    %0:gpr(s32) = G_LOAD %2(p0) :: (invariant load (s32) from %fixed-stack.1, align 16)
    %3:gpr(p0) = G_FRAME_INDEX %fixed-stack.0
    %1:gpr(s32) = G_LOAD %3(p0) :: (invariant load (s32) from %fixed-stack.0, align 4)
    %4:gpr(s32) = G_SREM %0, %1
    $eax = COPY %4(s32)
    RET 0, implicit $eax

...
